<html>
<head>
</head>
	<body>
	
	
	<?php
	/*
	echo "Sent by broswer:<br />";
	echo "x = " . $_GET['x'];
	echo "<br />";
	echo "y = " . $_GET['y'];
	*/
	
	error_reporting(E_ALL);

	/* Allow the script to hang around waiting for connections. */
	set_time_limit(0);

	/* Turn on implicit output flushing so we see what we're getting
	 * as it comes in. */
	ob_implicit_flush();

	$address = $_SERVER['SERVER_ADDR'];
	$port = 5566;
	
	//http://www.php.net/manual/en/sockets.constants.php
	//socket_create ( int $domain , int $type , int $protocol )
	//AF_INET is IPv4 Internet based protocols.
	//SOCK_DGRAM is connectionless, unreliable messages of a fixed maximum length). 
	//SOL_UDP represents the UDP protocol is based on this socket type.
	if (($sock = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP)) === false) {
		echo "socket_create() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
	}

	if ((socket_connect($sock, $address, $port)) === false) {
		echo "socket_connect() failed: reason: " . socket_strerror(socket_last_error()) . "\n";
	}
	
	//make a string to represent the coordinates and the origin
	//the origin is represented by a '1' indicating it is from the browser
	//the current offset is due to the video stream's upper left coner is 
	//at x = 72, and y = 17
	//if I did the math in the string, it would calculate the wrong numbers
	$x = (int)$_GET['x'] - 72; ;
	$y = (int)$_GET['y'] - 17;
	
	//the current stream is 640x480
	//if it's beyond that, it shouldn't be sent
	if(($x < 640) && ($y < 480) && ($x > 0) && ($y > 0)){
			$string =  $x  . "," . $y  . ",1\0";
			$bytesWritten = socket_write($sock, $string );
			
			echo "<br />";
			echo "String Written: $string<br />";
			echo "Bytes written: $bytesWritten";
	} else{
		echo "Coordinates were out of bounds";
	}
	
	
	
	

	//not necessary
	socket_close ($sock);
	?>
	
	

	</body>

</html>